package com.jlsoft;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import java.util.HashMap;
import java.util.Map;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * This class echoes a string called from JavaScript.
 */
public class JLAppHelper {

  public static final String PAY_ACTION = "com.ums.transcontroller.call";
  public static final String PRINT_ACTION = "com.ums.transcontroller.print";
  public static final String TRANS_APP_NAME = "appName";
  public static final String TRANS_BIZ_ID = "transId";
  public static final String TRANS_DATA = "transData";
  public static final String RESULT_CODE = "resultCode";
  public static final String RESULT_MSG = "resultMsg";
  public static final String PRINT_FILE_PATH = "filePath";
  private static final String RESULT = "result";
  public static final int TRANS_REQUEST_CODE = 1000;
  public static final int PRINT_REQUEST_CODE = 1001;

  public JLAppHelper() {
  }

  public static final Intent callTrans(Activity activity, String appName, String bizName, JSONObject transData) {
    Intent intent = new Intent();
    intent.setAction("com.ums.transcontroller.call");
    intent.putExtra("appName", appName);
    intent.putExtra("transId", bizName);
    intent.putExtra("transData", transData.toString());
//    activity.startActivityForResult(intent, 1000);
    return intent;
  }

  @SuppressLint({"NewApi"})
  public static final Map<String, String> filterTransResult(Intent data) {
    HashMap map = new HashMap();
    String result = data.getStringExtra("result");
    if(result != null && !result.isEmpty()) {
      System.out.println(result);

      try {
        JSONObject e = new JSONObject(result);
        map.put("appName", e.getString("appName"));
        map.put("transId", e.getString("transId"));
        map.put("resultCode", e.getString("resultCode"));
        map.put("resultMsg", e.getString("resultMsg"));
        map.put("transData", e.getString("transData"));
      } catch (JSONException var4) {
        var4.printStackTrace();
      }

      return map;
    } else {
      return map;
    }
  }

  public static final Intent callPrint(Activity activity, String filePath) {
    Intent intent = new Intent();
    intent.setAction("com.ums.transcontroller.print");
    intent.putExtra("filePath", filePath);
//    activity.startActivityForResult(intent, 1001);
    return intent;
  }

}
